package com.fcscs.ecms.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fcscs.cservice.ws.schema.urlservice.UrlInfo;
import com.fcscs.ecms.dao.ECMSGlobalProprietaryInfoDao;
import com.fcscs.ecms.dao.ECMSGlobalTextDao;
import com.fcscs.ecms.dao.ECMSUrlDao;
import com.fcscs.ecms.domain.GlobalProprietaryInfo;
import com.fcscs.ecms.domain.GlobalText;
import com.fcscs.ecms.domain.MdlUrlMain;
import com.fcscs.ecms.service.ECMSUrlManager;

/**
 * @author pvttinh
 * 
 */

@Service("ecmsUrlManager")
public class ECMSUrlManagerImpl implements ECMSUrlManager {

	@Autowired
	private ECMSUrlDao ecmsUrlDao;
	@Autowired
	private ECMSGlobalTextDao ecmsGlobalTextDao;
	@Autowired
	private ECMSGlobalProprietaryInfoDao ecmsGlobalProprietaryInfoDao;

	@Override
	public UrlInfo getUrlInfo(long moduleId, long orgId, long propId) throws Exception {
		// TODO Auto-generated method stub
		UrlInfo urlInfo = new UrlInfo();
		try{
			GlobalProprietaryInfo gpi = this.ecmsGlobalProprietaryInfoDao.find((int)orgId, (int)propId).get(0);
			
			MdlUrlMain mum = this.ecmsUrlDao.find((int)moduleId, gpi.getId()).get(0);
			urlInfo.setUrl(mum.getUrl());
			
			GlobalText gt = this.ecmsGlobalTextDao.get(mum.getNameRef(), "en_us");
			urlInfo.setTitle(gt.getTextUnicodeValue());
		}catch (Exception e) {
			// TODO: handle exception
			throw new Exception("Url.MANAGER.getUrlInfo() - " + e.getMessage());
		}
		
		return urlInfo;
	}
}
